//
//  LogViewController.m
//  MovieDate
//
//  Created by ann on 16/3/13.
//  Copyright © 2016年 MovieDate. All rights reserved.
//

#import "LogViewController.h"
#import "AppDelegate.h"
#import "NoteTestVC.h"
#import "ChangePassWordViewController.h"
@interface LogViewController ()
@property (weak, nonatomic) IBOutlet UITextField *userNameTXF;
@property (weak, nonatomic) IBOutlet UITextField *userPassWordTXF;


@end

@implementation LogViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    // Do any additional setup after loading the view from its nib.
}

- (void)initInfo {
    [super initInfo];
}

- (IBAction)btnPopAction:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)btnLoginAction:(id)sender
{
    NSString *identifierForVendor = [[NSUserDefaults standardUserDefaults] objectForKey:MACROS_KEY_DEVICE_TOKEN];
    [SVProgressHUD show];
    User *user = [User defaultUser];
    user.phone = self.userNameTXF.text;
    
    [TDNetwork loginPostURL:loginIP andphoneNumber:self.userNameTXF.text andPwd:self.userPassWordTXF.text andType:@"2" andMac:@"" andImsi:@"" andSystemName:@"" andSystemVersion:@"" andDeviceToke:identifierForVendor?identifierForVendor:self.userNameTXF.text andDeviceType:@"2" complete:^(BOOL succeed, NSString *ret, NSDictionary *dictionary) {
        UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *tabbar = [storyBoard instantiateInitialViewController];
        if (succeed)
        {
            switch ([ret intValue])
            {
                case 1:
                    [SVProgressHUD showSuccessWithStatus:@"登录成功"];
                    [self.navigationController presentViewController:tabbar animated:NO completion:nil];
                    break;
                    
                case -1:
                    [SVProgressHUD showErrorWithStatus:@"手机号或者密码不正确"];
                    break;
                    
                case -2:
                    [SVProgressHUD showErrorWithStatus:@"账户已冻结"];
                    break;
                    
                case -3:
                    [SVProgressHUD showErrorWithStatus:@"验证次数太多，稍后再试"];
                    break;
                    
                default:
                    [SVProgressHUD showErrorWithStatus:@"未知错误"];
                    break;
            }
            
            UIApplication *app = [UIApplication sharedApplication];
            AppDelegate *appDelegate = app.delegate;
            [appDelegate selCloseNoti];
        } else {
            [SVProgressHUD showErrorWithStatus:@"网络请求失败"];
        }
    }];
}

- (IBAction)btnUserRegisterAction:(id)sender {
    [self performSegueWithIdentifier:@"idfSMSVC" sender:nil];
}

- (IBAction)btnForgetPassWordAction:(id)sender {
    ChangePassWordViewController *changPSVC = [[ChangePassWordViewController alloc]init];
    [self.navigationController pushViewController:changPSVC animated:YES];
}

@end
